package thomas.bier.server;

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.apache.commons.lang.RandomStringUtils;

public class Mail {

	public void sendRegisterMail(String emailad){
		String s ="Beste...\n\n";
		s+="Activeer uw account op de website\n";
		s+="Uw activatiecode is: " + RandomStringUtils.randomAlphanumeric(8)+"\n";
		String msgBody = s;
		System.out.println(s);
		Properties props = new Properties(); 
		Session session = Session.getDefaultInstance(props, null); 
		try 
		{ 
			Message msg = new MimeMessage(session); 
			msg.setFrom(new InternetAddress("thomasch@gmail.com", "Bier admin")); 
			msg.addRecipient(Message.RecipientType.TO, new InternetAddress(emailad, "Gebruiker Bierdatabase")); 
			msg.setSubject("Uw VakantieVibes wachtwoord"); 
			msg.setText(msgBody); 
			Transport.send(msg);
		} 
		catch (AddressException e) 
		{ 
			e.printStackTrace(); 			
		} 
		catch (MessagingException e) 
		{ 
			e.printStackTrace(); 			
		} 
		catch (UnsupportedEncodingException e) 
		{ 
			e.printStackTrace();			
		} 
	}

}
